<?php
/* @var $this yii\web\View */
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\ActiveForm;
$this->title = '注册会员';
$this->params['breadcrumbs'][] = $this->title;
?>
<?php
if(!Yii::$app->user->isGuest){
 ?>
<div class="page-title">
  <div>
    <h1><i class="fa fa-user-plus"></i> 会员注册</h1>
    <ul class="breadcrumb side">
      <li><i class="fa fa-home fa-lg"></i></li>
      <li><a href="#">会员管理</a></li>
      <li class="active"><a href="#">会员注册</a></li>
    </ul>
  </div>
</div>

<!-- page body start -->
<div class="card">

<?php
}else{
 ?>
 <br>
<section class="container">
<div class="card">
  <a href="<?=Url::toRoute('site/login')?>" style='float:right;'><i class="fa fa-angle-left"></i> 返回登录页面</a>
  <h3 class="login-head"><i class="fa fa-lg fa-fw fa-user"></i>注 册</h3>
      <?php
    }
       ?>
       <div class='card-body'>
  <?php $form = ActiveForm::begin(); ?>

  <?php
    if(isset($tip)&&$tip===true){
      if($model->hasErrors()){
  ?>
        <div class="alert alert-danger" role="alert">
          <?php
              foreach($model->getErrors("") as $key=>$value){
                echo $value."<br>";
              }
          ?>
        </div>
  <?php
      }else{
  ?>
        <div class="alert alert-success" role="alert">贝恩资本风控部分已经收到您的注册申请，请耐心等待审核；我们通过审核后您将收到系统反馈短信，收到短信后请及时登录并修改您的登录密码，并记住您的用户名和新密码，谢谢合作！</div>
  <?php
      }
    }
  ?>
      <div class="form-group">
        <?=$form->field($model, 'name',['enableAjaxValidation'=>true]);?>
      </div>
      <div class="form-group">
        <?=$form->field($model, 'pw')->passwordInput()->hint("记住你的登录密码，用于下次登录使用，不能透露予他人")?>
      </div>
      <div class="form-group">
        <?=$form->field($model, 'phone',['enableAjaxValidation'=>true])?>
      </div>
      <div class="form-group">
        <?=$form->field($model, 'sms',['enableAjaxValidation'=>true])->label('短信验证码&nbsp;<button id="getsmsbtn" type="button" onclick="sendsms();">获取手机短信验证码</button>')?>
      </div>
      <div class="form-group">
        <?=$form->field($model, 'realname')?>
      </div>
      <div class="form-group">
        <?=$form->field($model, 'sfzid',['enableAjaxValidation'=>true])?>
      </div>
      <div class="form-group">
        <?=$form->field($model, 'bankcardid',['enableAjaxValidation'=>true])->hint('请如实填写中国境内有效的银行储蓄卡卡号')?> <!--国字头三大银行卡卡号(中国银行、中国农业银行、中国建设银行可以选择其中一家或者三个都要)-->
      </div>
      <div class="form-group">
        <?=$form->field($model, 'opencardbank')->hint('如：①中国XX银行XX支行 ②中国XX银行XX分理处 ③中国XX银行XX营业部')?>
      </div>
      <div class="form-group">
        <?=$form->field($model, 'alipay')->label('本人支付宝账号')?>
      </div>

      <div class="form-group">
        <?=$form->field($model, 'tjr',['enableAjaxValidation'=>true])->label('推荐人用户名')?>
      </div>
      <!--div class="form-group">
        $form->field($model, 'tjcode',['enableAjaxValidation'=>true])->hint('请向你的推荐人索要此推荐码')
      </div-->
      <div class="form-group">
        <?=$form->field($model, 'sfzimgfile')->fileInput()->hint('注意证件号码和人像清晰可辩，否则您的注册请求将会被风控部门驳回')?>
        <?php
          if(!isset($model->tjcode)||(is_null($model->tjcode))||($model->tjcode=='')){
            echo Html::img(Url::base().'/images/member.jpg',['class'=>'sfz-preview','style'=>'margin-bottom:20px;border:1px solid #ccc']);
          }else{
            echo Html::img(Url::base().'/'.$model->tjcode,['class'=>'sfz-preview','style'=>'margin-bottom:20px;border:1px solid #ccc']);
          }
        ?>
      </div>


      <div class="animated-checkbox">

        <label class="semibold-text">
          <?= $form->field($model, 'is_agree')->checkbox(['label' => '<span class="label-text"></span>']) ?>
        </label>
        <a href='<?=Url::toRoute('site/useagreement')?>' target='_blank'>网站使用协议 &gt;&gt;</a>

      </div>

      <div class="form-group">
          <?= Html::submitButton('<i class="fa fa-fw fa-lg fa-check-circle"></i>确认注册会员', ['class' => 'btn btn-warning']) ?>
      </div>


  <?php ActiveForm::end(); ?>
</div>
<?php
if(!Yii::$app->user->isGuest){
 ?>
 </div>
 <?php
 }
 else{
  ?>
</div>
<!-- footer content -->
<footer class="footer">
  <div class="container" style="text-align:center;color:white;">
    <br>
    Copyright © 2017 <?=$this->context->sysConfig->site_name?> 版权所有
    &nbsp;&nbsp;<span>|</span>
    &nbsp;&nbsp;<?=$this->context->sysConfig->site_reg_id?>
    &nbsp;&nbsp;<span>|</span>
    &nbsp;&nbsp;<a href="http://<?=$this->context->sysConfig->site_addr?>" target="_blank">关于<?=$this->context->sysConfig->site_name?></a>
  </div>
</footer>
<!-- /footer content -->
</section>
<?php
}
 ?>

<?php $this->beginBlock('getsmscode') ?>
var countdown=60;
function settime() {
   if (countdown == 0) {
        $('#getsmsbtn').removeAttr("disabled");
        $('#getsmsbtn').text("获取手机短信验证码");
        countdown = 60;
        return;
    } else {
        $('#getsmsbtn').attr("disabled", true);
        $('#getsmsbtn').text("重新获取验证码(" + countdown + ")");
        countdown--;
    }
  setTimeout(function() { settime() } ,1000)
}

function sendsms(){
    var phoneinvalid=$("#reguserform-phone").attr("aria-invalid");
    if(phoneinvalid==="true"){
      alert("请先输入正确的手机号码");
      return;
    }else{
      var phone=$("#reguserform-phone").val();
      if(phone.length>0){
        settime();
        var csrfToken = $('meta[name="csrf-token"]').attr("content");
        $.ajax({
          url:"<?=Url::toRoute('site/sendsms')?>",
          type:"get",
          datatype:"json",
          cache:false,
          data:{phone:phone,_csrf:csrfToken},
          success:function(data){
          console.log(data);
          },
          error:function(jqXHR,textStatus,errorThrown){
            console.log(jqXHR);
            console.log(textStatus);
            console.log(errorThrown);
          }
        });

      }else{
        alert("请先输入正确的手机号码");
        return;
      }
  }
}

$('#reguserform-sfzimgfile').change(function(){
  var fr=new FileReader();
  fr.onload=function(){
    var preview=this.result;
    $('#sfz-preview').prop('src',preview);
  }
  fr.readAsDataURL(this.files[0]);
});


<?php $this->endBlock() ?>
<?php $this->registerJs($this->blocks['getsmscode'],\yii\web\View::POS_END); ?>
<!-- page body end-->
